<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<!--标记面板-->
<!--<div class="modal fade" id="modal-add">
    <div class="modal-dialog" style="width: 400px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">新建调拨单</h4>
            </div>
            <div class="modal-body">
                <form id="modalForm" class="form-horizontal" role="form" style="margin-right: 50px">
                    <div class="form-group">
                        <label class="col-sm-4 control-label no-padding-right">调拨类型</label>
                        <div class="col-sm-8">
                            <select id="odrType" name="odrType" class="form-control" onchange="opt(value)">
                                <option value="" selected="selected">请选择</option>
                                <option value="1">外购件调拨</option>
                                <option value="2">原材料调拨</option>
                                <option value="3">外协件调拨</option>
                            </select>
                        </div>
                    </div>
                    <div id="typeDiv">
                        <div class="form-group">
                            <label class="col-sm-4 control-label no-padding-right">出库仓</label>
                            <div class="col-sm-8">
                                <select id="odrOutWhiId" name="odrOutWhiId" class="form-control">
                                    <option value="">全部</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-4 control-label no-padding-right">入库仓</label>
                            <div class="col-sm-8">
                                <select id="odrInWhiId" name="odrInWhiId" class="form-control">
                                    <option value="">全部</option>
                                </select>
                            </div>
                        </div>

                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label no-padding-right">备注</label>
                        <div class="col-sm-8">
                            <input type="text" id="odrRemark" name="odrRemark"
                                   class="form-control"
                                   placeholder="请输入备注">
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer" style="padding-top: 5px;">
                <button type="button" class="btn btn-info" id="btn-commit">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>

</div>-->
<section class="content-header">
    <h1 style="display: inline-block" id="title">调拨单审核</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <div class="row">
                        <div class="form-inline">
                            <form id="queryForm">
                                <div class="form-group">
                                    <label>
                                        调拨类型
                                    </label>
                                    <select name="odrType" class="form-control select">
                                        <option value="" selected>全部</option>
                                        <option value="1">外购件调拨</option>
                                        <option value="2">原材料调拨</option>
                                        <option value="3">外协件调拨</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>
                                        出库仓
                                    </label>
                                    <input name="odrOutWhiName" type="text" class="form-control text"
                                           placeholder="请输入出库仓"/>
                                </div>
                                <div class="form-group">
                                    <label>
                                        入库仓
                                    </label>
                                    <input name="odrInWhiName" type="text" class="form-control text" maxlength="255"
                                           placeholder="请输入入库仓"/>
                                </div>
                                <div class="form-group">
                                    <label>
                                        调拨单号
                                    </label>
                                    <input name="odrCode" type="text" class="form-control text" maxlength="255"
                                           placeholder="请输入调拨单号"/>
                                </div>
                                <div class="form-group">
                                    <label>
                                        制单人
                                    </label>
                                    <input name="odrMakePersonId" type="text" class="form-control text" maxlength="255"
                                           placeholder="请输入制单人"/>

                                </div>
                                <div class="form-group">
                                    <label>
                                        状态
                                    </label>
                                    <select name="odrStatus" class="form-control select">
                                        <option value="" selected>全部</option>
                                        <option value="2">未审核</option>
                                        <option value="3">审核通过</option>
                                    </select>
                                </div>
                                <!--<div class="form-group">
                                    <label>制单时间</label>
                                    <input type="text" class="form-control datepicker" id="startOdrMakeDate"
                                           name="startOdrMakeDate" readonly="readonly"/>
                                    <span>至</span>
                                    <input type="text" class="form-control datepicker" id="endOdrMakeDate"
                                           name="endOdrMakeDate" readonly="readonly"/>
                                </div>-->
                                <div class="form-group">
                                    <button type="button" class="btn btn-success" id="btn-search">搜索
                                    </button>
                                </div>
                            </form>
                        </div>
                    </div>

                </div>
                <!--<div id="toolbar">
                    <button id="btn_add" type="button" class="btn btn-info"  shiro:hasPermission="allocation:order:add">
                        新建
                    </button>
                </div>-->
                <div class="box-body">
                    <table id="bootstrap-table" class="table table-bordered " width="100%">
                    </table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var table;
    var appyStatusText = ["", "未提交", "未审核", "审核通过", "被驳回"];
    var colors = ['', "bg-gray", "bg-gray", "bg-green", "bg-red"];

    /**调拨类型下拉框获取仓库*/
    function opt(val){
        if(val==""){
            $("#typeDiv").hide();
        }else {
            js.post({
                url: ctx + "allocationOrder/findWar",
                data: {
                    odrType: val
                },
                success: function (result) {
                    $("#odrOutWhiId").empty();
                    $("#odrInWhiId").empty();
                    for (var i = 0; i < result.data.outWar.length; i++) {
                        $('#odrOutWhiId').append('<option value="' + result.data.outWar[i].whiId + '">' + result.data.outWar[i].whiName + '</option>');
                    }
                    for (var j = 0; j < result.data.inWar.length; j++) {
                        $('#odrInWhiId').append('<option value="' + result.data.inWar[j].whiId + '">' + result.data.inWar[j].whiName + '</option>');
                    }
                    $("#typeDiv").show();
                }
            })
        }
    }

    /**审核通过调拨单*/
    function commit(odrId){
        js.post({
            url: ctx + "allocationCheck/commit",
            data:{
                odrId:odrId
            },
            success: function (result) {
                js.modal.success(result.msg);
                js.table.refresh(table);
            }
        })
    }

    /**驳回调拨单*/
    function reject(odrId){

        js.modal.confirm("确定要驳回该调拨单吗？", function (result) {
            js.post({
                url: ctx + "allocationCheck/reject",
                data:{
                    odrId:odrId
                },
                success: function (result) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                }
            })
        })
    }

    /**
     * 撤销审核通过
     * @param odrId
     */
    function revoke(odrId){
        js.post({
            url: ctx + "allocationCheck/revoke",
            data:{
                odrId:odrId
            },
            success: function (result) {
                js.modal.success(result.msg);
                js.table.refresh(table);
            }
        })
    }

    $(function () {
        //加载列表数据
        table = js.table.init({
            id: 'bootstrap-table',
            url: ctx + "allocationCheck/list",
            showColumns: true,
            showExport: false,
            pageSize: 300,
            striped: false,
            uniqueId: "odrId",
            columns: [
                {
                    title: '序号', field: 'odrId', width: '40',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: '调拨单号', field: 'odrCode'},
                {title: '调拨类型', field: 'odrType',
                    formatter: function (value, row, index) {
                    if(value == 1){
                        return "外购件调拨";
                    }else if(value == 2){
                        return "原材料调拨";
                    }else if(value == 3){
                        return "外协件调拨";
                    }else {
                        return value;
                    }
                    }},
                {title: '出库仓', field: 'odrOutWhiName'},
                {title: '入库仓', field: 'odrInWhiName'},
                {title: '备注', field: 'odrRemark'},
                {title: '制单人', field: 'odrMakePersonId'},
                {title: '出入库状态', field: 'odrOutStatus',visible: false
                },
                {title: '状态', field: 'odrStatus',
                    formatter: function (value, row, index) {
                        /*if(value == 2){
                            return "未审核"
                        }else if(value == 3){
                            return "审核通过"
                        }else if(value == 4){
                            return "已驳回"
                        }else {
                            return value
                        }*/
                        if (value == undefined) {
                            return "";
                        }
                        return '<span class="badge ' + colors[value] + '">' + appyStatusText[value] + '</span> ';
                    }
                },
                {
                    title: '操作', field: 'odrId',width:'170',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if((row.odrStatus == 3 || row.odrStatus == 2 || row.odrOutStatus == 2 || row.odrOutStatus == 3) && hasP("allocation:orderapp:vew")){
                            actions.push('<a class="btn btn-info btn-xs" href="/allocationOrder/allocationOrderDetailView/' + row.odrId + '">查看</a>');
                        }
                        if(row.odrStatus == 2 && hasP("allocation:orderapp:edit")){
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="commit(' + row.odrId + ')">通过</a>');
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="reject(' + row.odrId + ')">驳回</a>');
                        }
                        if(row.odrStatus == 3 && row.odrOutStatus == 1 && hasP("allocation:orderapp:edit")){
                            actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="revoke(' + row.odrId + ')">撤销</a>');
                        }
                        return actions.join('');
                    }
                }
            ]
        });
        /**
         * 表格搜索
         */
        $("#btn-search").on('click', function () {
            js.table.search(table);
        });

        /**
         * 点击新建
         */
        $("#btn_add").on('click', function () {
            js.modal.open("modal-add");
        });

        /**
         * 新建弹出框打开事件
         */
        js.modal.openEvent("modal-add", function () {
            $("#typeDiv").hide();
        });

        js.modal.hideEvent("modal-add", function () {
            js.reset("modalForm");
        });

        /**
         * 创建调拨单保存
         */
        $("#btn-commit").on('click', function () {
            if($("#odrType").val() == ""){
                js.modal.warning("请选择调拨类型！");
                return;
            }
            js.submit({
                url: ctx + "allocationOrder/saveAllocationOrder",
                data: new FormData($("#modalForm")[0]),
                success: function (result) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                    js.modal.hide("modal-add");
                }
            })
        });
    });
</script>
</body>
</html>
